<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Rails::Console</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            Rails::Console 
            
                <span class="parent">&lt; 
                    
                    <a href="../Object.html">Object</a>
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../files/railties/lib/rails/commands/console_rb.html">railties/lib/rails/commands/console.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>D</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Console.html#method-i-debugger-3F">debugger?</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>E</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Console.html#method-i-environment">environment</a>,
              </li>
            
              
              <li>
                <a href="Console.html#method-i-environment-3F">environment?</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Console.html#method-c-new">new</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>P</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Console.html#method-c-parse_arguments">parse_arguments</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>R</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Console.html#method-i-require_debugger">require_debugger</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Console.html#method-i-sandbox-3F">sandbox?</a>,
              </li>
            
              
              <li>
                <a href="Console.html#method-i-set_environment-21">set_environment!</a>,
              </li>
            
              
              <li>
                <a href="Console.html#method-i-start">start</a>,
              </li>
            
              
              <li>
                <a href="Console.html#method-c-start">start</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    
      <!-- Section attributes -->
      <div class="sectiontitle">Attributes</div>
      <table border='0' cellpadding='5'>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>app</td>
            <td class='attr-desc'></td>
          </tr>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>console</td>
            <td class='attr-desc'></td>
          </tr>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>options</td>
            <td class='attr-desc'></td>
          </tr>
        
      </table>
    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>(app, options={})
            
            <a href="Console.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be3e10cd26bc8ec29c6474d03a08a8e733108e7d/railties/lib/rails/commands/console.rb#L46" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/console.rb, line 46</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>(<span class="ruby-identifier">app</span>, <span class="ruby-identifier">options</span>={})
  <span class="ruby-ivar">@app</span>     = <span class="ruby-identifier">app</span>
  <span class="ruby-ivar">@options</span> = <span class="ruby-identifier">options</span>

  <span class="ruby-identifier">app</span>.<span class="ruby-identifier">sandbox</span> = <span class="ruby-identifier">sandbox?</span>
  <span class="ruby-identifier">app</span>.<span class="ruby-identifier">load_console</span>

  <span class="ruby-ivar">@console</span> = <span class="ruby-identifier">app</span>.<span class="ruby-identifier">config</span>.<span class="ruby-identifier">console</span> <span class="ruby-operator">||</span> <span class="ruby-constant">IRB</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-parse_arguments">
            
              <b>parse_arguments</b>(arguments)
            
            <a href="Console.html#method-c-parse_arguments" name="method-c-parse_arguments" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-parse_arguments_source')" id="l_method-c-parse_arguments_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be3e10cd26bc8ec29c6474d03a08a8e733108e7d/railties/lib/rails/commands/console.rb#L12" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-parse_arguments_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/console.rb, line 12</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">parse_arguments</span>(<span class="ruby-identifier">arguments</span>)
  <span class="ruby-identifier">options</span> = {}

  <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">opt</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">opt</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-string">&quot;Usage: rails console [environment] [options]&quot;</span>
    <span class="ruby-identifier">opt</span>.<span class="ruby-identifier">on</span>(<span class="ruby-string">'-s'</span>, <span class="ruby-string">'--sandbox'</span>, <span class="ruby-string">'Rollback database modifications on exit.'</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:sandbox</span>] = <span class="ruby-identifier">v</span> }
    <span class="ruby-identifier">opt</span>.<span class="ruby-identifier">on</span>(<span class="ruby-string">&quot;-e&quot;</span>, <span class="ruby-string">&quot;--environment=name&quot;</span>, <span class="ruby-constant">String</span>,
            <span class="ruby-string">&quot;Specifies the environment to run this console under (test/development/production).&quot;</span>,
            <span class="ruby-string">&quot;Default: development&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:environment</span>] = <span class="ruby-identifier">v</span>.<span class="ruby-identifier">strip</span> }
    <span class="ruby-identifier">opt</span>.<span class="ruby-identifier">on</span>(<span class="ruby-string">&quot;--debugger&quot;</span>, <span class="ruby-string">'Enable the debugger.'</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:debugger</span>] = <span class="ruby-identifier">v</span> }
    <span class="ruby-identifier">opt</span>.<span class="ruby-identifier">parse!</span>(<span class="ruby-identifier">arguments</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">arguments</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">arguments</span>.<span class="ruby-identifier">first</span>[<span class="ruby-number">0</span>] <span class="ruby-operator">!=</span> <span class="ruby-string">'-'</span>
    <span class="ruby-identifier">env</span> = <span class="ruby-identifier">arguments</span>.<span class="ruby-identifier">first</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">available_environments</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">env</span>
      <span class="ruby-identifier">options</span>[<span class="ruby-value">:environment</span>] = <span class="ruby-identifier">env</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">options</span>[<span class="ruby-value">:environment</span>] = <span class="ruby-node">%w(production development test)</span>.<span class="ruby-identifier">detect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span> <span class="ruby-operator">=~</span> <span class="ruby-node">/^#{env}/</span>} <span class="ruby-operator">||</span> <span class="ruby-identifier">env</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">options</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-start">
            
              <b>start</b>(*args)
            
            <a href="Console.html#method-c-start" name="method-c-start" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-start_source')" id="l_method-c-start_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be3e10cd26bc8ec29c6474d03a08a8e733108e7d/railties/lib/rails/commands/console.rb#L8" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-start_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/console.rb, line 8</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">start</span>(*<span class="ruby-identifier">args</span>)
  <span class="ruby-identifier">new</span>(*<span class="ruby-identifier">args</span>).<span class="ruby-identifier">start</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-debugger-3F">
            
              <b>debugger?</b>()
            
            <a href="Console.html#method-i-debugger-3F" name="method-i-debugger-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-debugger-3F_source')" id="l_method-i-debugger-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be3e10cd26bc8ec29c6474d03a08a8e733108e7d/railties/lib/rails/commands/console.rb#L72" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-debugger-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/console.rb, line 72</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">debugger?</span>
  <span class="ruby-identifier">options</span>[<span class="ruby-value">:debugger</span>]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-environment">
            
              <b>environment</b>()
            
            <a href="Console.html#method-i-environment" name="method-i-environment" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-environment_source')" id="l_method-i-environment_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be3e10cd26bc8ec29c6474d03a08a8e733108e7d/railties/lib/rails/commands/console.rb#L60" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-environment_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/console.rb, line 60</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">environment</span>
  <span class="ruby-identifier">options</span>[<span class="ruby-value">:environment</span>] <span class="ruby-operator">||=</span> <span class="ruby-constant">ENV</span>[<span class="ruby-string">'RAILS_ENV'</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">ENV</span>[<span class="ruby-string">'RACK_ENV'</span>] <span class="ruby-operator">||</span> <span class="ruby-string">'development'</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-environment-3F">
            
              <b>environment?</b>()
            
            <a href="Console.html#method-i-environment-3F" name="method-i-environment-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-environment-3F_source')" id="l_method-i-environment-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be3e10cd26bc8ec29c6474d03a08a8e733108e7d/railties/lib/rails/commands/console.rb#L64" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-environment-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/console.rb, line 64</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">environment?</span>
  <span class="ruby-identifier">environment</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-require_debugger">
            
              <b>require_debugger</b>()
            
            <a href="Console.html#method-i-require_debugger" name="method-i-require_debugger" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-require_debugger_source')" id="l_method-i-require_debugger_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be3e10cd26bc8ec29c6474d03a08a8e733108e7d/railties/lib/rails/commands/console.rb#L93" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-require_debugger_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/console.rb, line 93</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">require_debugger</span>
  <span class="ruby-identifier">require</span> <span class="ruby-string">'debugger'</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;=&gt; Debugger enabled&quot;</span>
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">LoadError</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;You're missing the 'debugger' gem. Add it to your Gemfile, bundle, and try again.&quot;</span>
  <span class="ruby-identifier">exit</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-sandbox-3F">
            
              <b>sandbox?</b>()
            
            <a href="Console.html#method-i-sandbox-3F" name="method-i-sandbox-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-sandbox-3F_source')" id="l_method-i-sandbox-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be3e10cd26bc8ec29c6474d03a08a8e733108e7d/railties/lib/rails/commands/console.rb#L56" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-sandbox-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/console.rb, line 56</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">sandbox?</span>
  <span class="ruby-identifier">options</span>[<span class="ruby-value">:sandbox</span>]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-set_environment-21">
            
              <b>set_environment!</b>()
            
            <a href="Console.html#method-i-set_environment-21" name="method-i-set_environment-21" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-set_environment-21_source')" id="l_method-i-set_environment-21_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be3e10cd26bc8ec29c6474d03a08a8e733108e7d/railties/lib/rails/commands/console.rb#L68" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-set_environment-21_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/console.rb, line 68</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">set_environment!</span>
  <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">env</span> = <span class="ruby-identifier">environment</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-start">
            
              <b>start</b>()
            
            <a href="Console.html#method-i-start" name="method-i-start" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-start_source')" id="l_method-i-start_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be3e10cd26bc8ec29c6474d03a08a8e733108e7d/railties/lib/rails/commands/console.rb#L76" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-start_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/console.rb, line 76</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">start</span>
  <span class="ruby-identifier">require_debugger</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">debugger?</span>
  <span class="ruby-identifier">set_environment!</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">environment?</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">sandbox?</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Loading #{Rails.env} environment in sandbox (Rails #{Rails.version})&quot;</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;Any modifications you make will be rolled back on exit&quot;</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Loading #{Rails.env} environment (Rails #{Rails.version})&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">if</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-identifier">console</span><span class="ruby-operator">::</span><span class="ruby-constant">ExtendCommandBundle</span>)
    <span class="ruby-identifier">console</span><span class="ruby-operator">::</span><span class="ruby-constant">ExtendCommandBundle</span>.<span class="ruby-identifier">send</span> <span class="ruby-value">:include</span>, <span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">ConsoleMethods</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">console</span>.<span class="ruby-identifier">start</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    